<?php
namespace jy_cun9fan;
defined('BY_JYA') or exit('error');
/*
	任务
*/
class task extends \plugin{
    public function jifen_sf($setting=array()){
		if($setting){
			$this->setting=$setting;
		}
        if(!$this->setting['is_open']){
            return false;
        }
		$this->model('model')->up_redfee();
		$this->model('model')->up_del_day();
        $daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
        $fanlogs = $this->pdo_getall('fanlog',array('uniacid'=>$_SESSION['uniacid'],'status'=>array(0,2),'uptime <'=>$daytime));
        if(!$fanlogs){
          return false;
        }
		$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
		$lastdaytime=$daytime-24*3600;
		$dayallfee=pdo_getsum('core_recharge',array('status'=>1,'uniacid'=>$_SESSION['uniacid'],'pluginname'=>'jy_cun9fan','createtime between'=>array($lastdaytime,$daytime)),'fee');
		$fannum = count($fanlogs);
		if($fannum && $this->setting['fandayfee']){
			$fandayfee=$dayallfee*$this->setting['fandayfee']/(100*$fannum);
        }
		if(!$fandayfee || $fandayfee<=0){
			//取营业额最大值
			//return false;
		}
        foreach($fanlogs as $item){
			$item['isfandayfee']=1;
			$this->model('commission')->up_fanone($item,$fandayfee);
        }
        return true;
    }
}